#include <iostream>
#include <string.h>

using namespace std;
/* 构造函数 */
class Student
{
public:
    int m_num;
    char* m_name;
    int m_age;

public:
    // Student() = default;
    Student()
    {
        cout<<"无参数构造函数"<<endl;
    }

    #if 1
    Student(int num, const char *name ,int age)
    {   
        cout<<"student"<<endl;

        m_num = num;

        int len = strlen(name);
        m_name = new char[len + 1];
        strcpy(m_name, name);
        
        m_age = age;
    }

    Student(const char *name)
    {   
        m_age = 0;
        m_num = 1;
        int len = strlen(name);
        m_name = new char[len + 1];
        strcpy(m_name, name);
    }

    /* 拷贝构造函数 */
    Student(const Student &other)
    {   
        cout<<"Student copy Student"<<endl;
        this->m_num = other.m_num;
        this->m_age = other.m_age;
        this->m_name = other.m_name;
    }

    /* =运算符重载函数 */
    Student & operator=(const Student &other)
    {   
        cout<<"Student copy Student"<<endl;
        this->m_num = other.m_num;
        this->m_age = other.m_age;
        this->m_name = other.m_name;
        return *this;
    }
    

    explicit Student(int age)//类型转换:一个参数
    {   
        m_age = age;
    }

    operator int()
    {
        return m_age;
    }

    ~Student()
    {
        cout<<"end"<<endl;
        // delete []m_name;
        // m_name = nullptr;
    }
    #endif
};

int main()
{
    #if 0
    // Student stu(1, "大黑", 300);
    Student stu(1);
    Student stu2("日和");
    int age = static_cast<int>(stu);
    // int age = stu.operator int();
    cout<<age<<endl;
    #endif
    
    Student stu(1, "大黑", 300);
    // Student stu2 = stu;//初始化：调用拷贝构造函数

    Student stu2;
    /* 以下两种用法作用相同 */
    stu2 = stu;//调用：调用：调用=运算符重载函数
    stu2.operator=(stu);

    /* Student属于自定义类型， */
    cout<<"stu2.m_name"<<stu2.m_name<<endl;
    Student stu3(stu2);
    cout<<"stu3.m_name"<<stu3.m_name<<endl;
}